package com.com.knowledgepaymentmanagementsystem.controller.marketing;

import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Give;

import com.com.knowledgepaymentmanagementsystem.service.marketing.GiveService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DELL
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 15:08
 */
@RestController
@Api(tags = "满赠管理")
@CrossOrigin
@RequestMapping("/give")
public class GiveController {
    @Autowired
    private GiveService giveService;
    @ApiOperation(value = "查询满赠", httpMethod = "POST", notes = "查询满赠")
    @PostMapping("/find")
    public ResultUtil<List<Give>> getGives(@RequestBody Give give) {
        List<Give> gives = giveService.getGive(give);
        try {
            return new ResultUtil<>(200, "查询成功", gives);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询失败");

        }
    }

    @ApiOperation(value = "新增满赠", httpMethod = "POST", notes = "新增满赠")
    @PostMapping("insert")
    public ResultUtil insertGive(@RequestBody Give give) {
        try {
            return new ResultUtil<>(200, "新增成功", giveService.insertGive(give));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "新增失败");
        }
    }

    @ApiOperation(value = "删除满赠", httpMethod = "DELETE", notes = "删除满赠")
    @DeleteMapping("delete")
    public ResultUtil deleteGive(@RequestParam Integer giveId) {
        try {
            giveService.deleteGive(giveId);
            return new ResultUtil<>(200, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "删除失败");
        }
    }

    @ApiOperation(value = "修改满赠", httpMethod = "PUT", notes = "修改满赠")
    @PutMapping("update")
    public ResultUtil updateGive(@RequestBody Give give) {
        try {
            giveService.updateGive(give);
            return new ResultUtil<>(200, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "修改失败");
        }
    }





}
